#!/bin/bash
echo "=== 完整修复UEStudio构建 ==="

export PATH="/c/msys64/ucrt64/bin:$PATH"

cd /d/vc/UEStudio

# 1. 恢复原始构建文件
echo "1. 恢复原始构建文件..."
cp "/d/CB2503/codeblocks_25.03/configure.ac" .
cp "/d/CB2503/codeblocks_25.03/Makefile.am" .
cp "/d/CB2503/codeblocks_25.03/bootstrap" .
cp "/d/CB2503/codeblocks_25.03/src/plugins/Makefile.am" "src/plugins/"
chmod +x bootstrap

# 2. 恢复插件目录
echo "2. 恢复插件目录..."
for dir in configmanager_common configmanager_importers configmanager_exporters; do
    rm -rf "src/plugins/$dir"
    cp -r "/d/CB2503/codeblocks_25.03/src/plugins/$dir" "src/plugins/" 2>/dev/null || mkdir -p "src/plugins/$dir"
done

# 3. 重新生成构建系统
echo "3. 重新生成构建系统..."
./bootstrap

# 4. 配置和构建
echo "4. 配置和构建..."
./configure --with-wx-config=/c/msys64/ucrt64/bin/wx-config --enable-debug
make -j4

if [ $? -eq 0 ]; then
    echo "🎉 UEStudio构建成功！"
else
    echo "❌ 构建失败"
fi
